// 获取返回的树
function getMenuList(){
    let init = JSON.parse(window?._init) || {};
    const menuList = [...init?.barPageList, ...init?.morePageList];
    return menuList;
}

// 递归找key
function filterKey(data, key) {
    let result = '';
    data && data.forEach((item) => {
        if(item.url === key) {
            result = item.menuKey;
        }else {
            if (item.menuList && item.menuList.length) {
                let id = filterKey(item.menuList, key);
                if(id) result = id;
            }
        }
    });

    return result;
}

// TODO 暂时先这样
// 获取侧边栏ID
export function getMenuItemId(key){
    const data = getMenuList();
    return filterKey(data, key);
}